package com.ruoyi.ZhuNong.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ZhuNong.domain.NbAgroProduce;
import com.ruoyi.ZhuNong.service.INbAgroProduceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农产品Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/ZhuNong/produce")
public class NbAgroProduceController extends BaseController
{
    @Autowired
    private INbAgroProduceService nbAgroProduceService;

    /**
     * 查询农产品列表
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbAgroProduce nbAgroProduce)
    {
        startPage();
        List<NbAgroProduce> list = nbAgroProduceService.selectNbAgroProduceList(nbAgroProduce);
        return getDataTable(list);
    }

    /**
     * 导出农产品列表
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:export')")
    @Log(title = "农产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbAgroProduce nbAgroProduce)
    {
        List<NbAgroProduce> list = nbAgroProduceService.selectNbAgroProduceList(nbAgroProduce);
        ExcelUtil<NbAgroProduce> util = new ExcelUtil<NbAgroProduce>(NbAgroProduce.class);
        util.exportExcel(response, list, "农产品数据");
    }

    /**
     * 获取农产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nbAgroProduceService.selectNbAgroProduceById(id));
    }

    /**
     * 新增农产品
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:add')")
    @Log(title = "农产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbAgroProduce nbAgroProduce)
    {
        return toAjax(nbAgroProduceService.insertNbAgroProduce(nbAgroProduce));
    }

    /**
     * 修改农产品
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:edit')")
    @Log(title = "农产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbAgroProduce nbAgroProduce)
    {
        return toAjax(nbAgroProduceService.updateNbAgroProduce(nbAgroProduce));
    }

    /**
     * 删除农产品
     */
    @PreAuthorize("@ss.hasPermi('ZhuNong:produce:remove')")
    @Log(title = "农产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbAgroProduceService.deleteNbAgroProduceByIds(ids));
    }
}
